package com.jl.jlapp.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.ActivityNameCouponListAdapter;
import com.jl.jlapp.adapter.ActivityNameGoodsListAdapter;
import com.jl.jlapp.eneity.ActivityInformationByIdModel;
import com.jl.jlapp.eneity.ActivityInformationByIdModel.ResultDataBean.CouponInformationBean;
import com.jl.jlapp.eneity.ActivityInformationByIdModel.ResultDataBean.GoodsBean;
import com.jl.jlapp.eneity.CommitVatInvoiceAptitudeToCheckModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.utils.CustomGridLayoutManager;

import org.reactivestreams.Subscription;

import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class ActivityNameActivity
        extends Activity {
    @BindView(R.id.activity_coupon_recycle_view)
    RecyclerView activityCouponRecycleView;
    @BindView(R.id.activity_end_time)
    TextView activityEndTime;
    @BindView(R.id.activity_goods_recycle_view)
    RecyclerView activityGoodsRecycleView;
    @BindView(R.id.activity_img)
    ImageView activityImg;
    int activityInformationId = 0;
    @BindView(R.id.activity_introduce)
    TextView activityIntroduce;
    String activityName = "";
    ActivityNameCouponListAdapter activityNameCouponListAdapter;
    ActivityNameGoodsListAdapter activityNameGoodsListAdapter;
    @BindView(R.id.activity_start_time)
    TextView activityStartTime;
    int activityType = -1;
    List<ActivityInformationByIdModel.ResultDataBean.CouponInformationBean> couponInformationBeanList = new ArrayList();
    int fromPage = -1;
    List<ActivityInformationByIdModel.ResultDataBean.GoodsBean> goodsBeanList = new ArrayList();
    SharedPreferences sharedPreferences;
    List<String> strings;
    int userId = 0;

    private void getNetData() {
        Net.get().getActivityInformationById(this.activityInformationId).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonObserver<ActivityInformationByIdModel>() {

                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(ActivityInformationByIdModel activityInformationByIdModel) {

                    }
                });
    }

    private void setActivityNameCouponListAdapter() {
        this.activityCouponRecycleView.setLayoutManager(new CustomGridLayoutManager(this, 3, false));
        this.activityNameCouponListAdapter = new ActivityNameCouponListAdapter(R.layout.activity_name_coupon_item_layout, this.couponInformationBeanList);
        this.activityCouponRecycleView.setAdapter(this.activityNameCouponListAdapter);
        this.activityNameCouponListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                paramAnonymousInt = ((ActivityInformationByIdModel.ResultDataBean.CouponInformationBean) ActivityNameActivity.this.couponInformationBeanList.get(paramAnonymousInt)).getId();
                ActivityNameActivity.this.userId = ActivityNameActivity.this.sharedPreferences.getInt("userId", 0);
                if (ActivityNameActivity.this.userId == 0) {
                    Toast.makeText(ActivityNameActivity.this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(ActivityNameActivity.this, LoginActivity.class);
                    ActivityNameActivity.this.startActivity(intent);
                }
                Net.get().userGetCoupon(paramAnonymousInt, ActivityNameActivity.this.userId).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new CommonObserver<CommitVatInvoiceAptitudeToCheckModel>() {

                            @Override
                            protected void onError(String errorMsg) {

                            }

                            @Override
                            protected void onSuccess(CommitVatInvoiceAptitudeToCheckModel o) {

                            }
                        });
            }
        });
    }

    private void setActivityNameGoodsListAdapter() {
        this.activityGoodsRecycleView.setLayoutManager(new CustomGridLayoutManager(this, 4, false));
        this.activityNameGoodsListAdapter = new ActivityNameGoodsListAdapter(R.layout.activity_name_goods_item_layout, this.goodsBeanList);
        this.activityGoodsRecycleView.setAdapter(this.activityNameGoodsListAdapter);
        this.activityNameGoodsListAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                paramAnonymousInt = ((ActivityInformationByIdModel.ResultDataBean.GoodsBean) ActivityNameActivity.this.goodsBeanList.get(paramAnonymousInt)).getId();
                Intent intent = new Intent(ActivityNameActivity.this, GoodsDetailActivity.class);
                if (ActivityNameActivity.this.activityType == 5) {
                    intent.putExtra("activityId", ActivityNameActivity.this.activityInformationId);
                    intent.putExtra("activityName", ActivityNameActivity.this.activityName);
                    intent.putExtra("goodsId", paramAnonymousInt);
                    ActivityNameActivity.this.startActivity(intent);
                }
            }
        });
    }

    @OnClick({R.id.icon_return})
    public void onClick(View paramView) {
        Intent intent = new Intent(this, BaseActivity.class);
        startActivity(intent);
        finish();
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_name);
        ButterKnife.bind(this);
        this.sharedPreferences = getSharedPreferences("JLAppData", 0);
        this.userId = this.sharedPreferences.getInt("userId", 0);
        Intent intent = getIntent();
        this.activityInformationId = intent.getIntExtra("activityInformationId", 0);
        this.fromPage = intent.getIntExtra("isFromScreenActivity", -1);
        if (this.activityInformationId > 0) {
            getNetData();
        } else {
            setActivityNameCouponListAdapter();
            setActivityNameGoodsListAdapter();
            Toast.makeText(this, "页面传值没有收到", Toast.LENGTH_SHORT).show();
            return;
        }
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if (paramInt == 4) {
            if (this.fromPage != -1) {
                finish();
            }
        } else {
            Intent localIntent = new Intent(this, BaseActivity.class);
            startActivity(localIntent);
            finish();
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/ActivityNameActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */